var Kangjunyaowu = new Vue({
    el : "#Kangjunyaowulist",
    data :{
        xiangmuId : $("#xiangmuId").val(),
        xiangmu : {},
        kangjunyaowu :{},
        kangjunyaowulist : [],
        show : false,					// 显示列表是否有数据

        pageIndex : 1,
        pageSize :80,
        pageCount : 0,
        recordCount : 0,
        inputPageIndexValue : "",

    },

    created : function() {
        var _this = this;
        xiangmuId=_this.xiangmuId;
        _this.bindKangjunyaowuList();
        _this.bindXiangmu();

    },
    methods : {
        toback : function() {
            window.history.go(-1);
        },
        bindXiangmu:function (){
            var _this = this;
            layer.open({type:3});
            $.post('/xiangmu/find_one', {
                xianmguid : _this.xiangmuId,
                rdm : Math.random()
            },function(ppData) {
                layer.closeAll("loading");
                if(ppData != null){
                    if(ppData.result == "1"){
                        var data = ppData.resultContent;
                        _this.xiangmu = data;
                    }else{
                        layer.alert(ppData.message);
                    }
                }
            },"json");
        },
        toDelete:function (){
            var _this = this;

            layer.confirm("确定删除该项目的材料吗？",{
                btn : ['是','否']
            },function(){
                layer.open({type:3});

                $.post("/kangjunyaowu/delete", {
                    xiangmuid : _this.xiangmuId,
                    random : Math.random()
                }, function(ppData) {
                    if (ppData != null) {
                        layer.closeAll("loading");

                        if(ppData.result != "1"){
                            layer.alert(ppData.message);
                        }else{
                            layer.open({
                                time:1000,
                                btn:[],
                                content:"删除成功!",
                            });

                            _this.bindKangjunyaowuList();
                            _this.bindXiangmu();
                        }
                    }
                },"json");
            })
        },

        bindKangjunyaowuList:function (){
            var _this = this;
            layer.open({type:3});
            $.post("/kangjunyaowu/findkangjunyaowulist",{
                xiangmuid : _this.xiangmuId,
                pageindex : _this.pageIndex,
                pagesize : _this.pageSize,
                rdm : Math.random()
            },function(ppData){
                layer.closeAll("loading");
                if (ppData != null){
                    if(ppData.result == "1"){
                        var data=ppData.resultContent;
                        var mmHtml = "<table class=\"table table-hover table-bordered\" style=\"overflow:hidden; margin-bottom:10px;table-layout:fixed;\" v-if=\"show\" cellspacing=\"0\" cellpadding=\"0\">\n" +
                           /* "   <thead >\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;width:50px;\" >品种</th>\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;width:50px;\" >品规</th>\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;\" >药品名称</th>\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;\" >分类</th>\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;\" >品种/品规限制</th>\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;\" >规格</th>\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;\" >价格(元）</th>\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;width:50px;\" >单位</th>\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;\" >医保类别</th>\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;width:50px;\" >基药</th>\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;width:50px;\" >集采药</th>\n" +
                           /!* "       <th style=\"text-align:center;vertical-align:middle;width:50px;\" >一致性评价</th>\n" +*!/
                            "       <th style=\"text-align:center;vertical-align:middle;width:50px;\" >15版指导原则</th>\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;width:50px;\" >院本部药</th>\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;width:80px;\" >半年无采购记录</th>\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;width:50px;\" >秦淮药</th>\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;width:80px;\" >半年无采购记录</th>\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;\" >药学建议</th>\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;\" >备注</th>\n" +
                            "    </thead>";*/
                       "   <thead >\n" +
                       "    <tr style=\"font-weight: bold;\">\n" +
                       "        <td style=\"text-align:center;vertical-align:middle;width:50px;\" rowspan=\"2\">品种</td>\n" +
                       "        <td style=\"text-align:center;vertical-align:middle;width:50px;\" rowspan=\"2\" >品规</td>\n" +
                       "        <td style=\"text-align:center;vertical-align:middle;\" rowspan=\"2\" >药品名称</td>\n" +
                       "        <td style=\"text-align:center;vertical-align:middle;\" rowspan=\"2\" >分类</td>\n" +
                       "        <td style=\"text-align:center;vertical-align:middle;\" rowspan=\"2\" >规格</td>\n" +
                       "        <td style=\"text-align:center;vertical-align:middle;\" rowspan=\"2\" >单位</td>\n" +
                       "        <td style=\"text-align:center;vertical-align:middle;\" rowspan=\"2\" >医保类别</td>\n" +
                       "        <td style=\"text-align:center;vertical-align:middle;\"colspan=\"4\" >推荐依据</td>\n" +
                       "        <td style=\"text-align:center;vertical-align:middle;\" colspan=\"2\">所在目录</td>\n" +
                       "        <td style=\"text-align:center;vertical-align:middle;\" colspan=\"2\">半年无采购记录</td>\n" +
                       "        <td style=\"text-align:center;vertical-align:middle;\"colspan=\"2\" >抗菌药物管理工作小组预选意见</td>\n" +
                       "    </tr>\n" +
                       "    <tr style=\"font-weight: bold;\">\n" +
                       "        <td style=\"text-align:center;vertical-align:middle;\" >基药</td>\n" +
                       "        <td style=\"text-align:center;vertical-align:middle;\" >集采药</td>\n" +
                       "        <td style=\"text-align:center;vertical-align:middle;\" >一致性评价</td>\n" +
                       "        <td style=\"text-align:center;vertical-align:middle;\" >15版指导原则</td>\n" +
                       "        <td style=\"text-align:center;vertical-align:middle;\" >院本部</td>\n" +
                       "        <td style=\"text-align:center;vertical-align:middle;\" >秦淮</td>\n" +
                       "        <td style=\"text-align:center;vertical-align:middle;\" >院本部</td>\n" +
                       "        <td style=\"text-align:center;vertical-align:middle;\" >秦淮</td>\n" +
                       "        <td style=\"text-align:center;vertical-align:middle;\" >是否为前48个品种</td>\n" +
                       "        <td style=\"text-align:center;vertical-align:middle;\" >品规得票（总票数25）</td>\n" +
                       "    </tr>\n" ;
                        "    </thead>";
                   if(data.KangjunyaowuList.length > 0){
                       _this.show = true;
                       _this.kangjunyaowulist=data.KangjunyaowuList;

                       var PageInfo = data.PageInfo;
                       _this.pageIndex = PageInfo.pageIndex;
                       _this.recordCount = PageInfo.recordCount;
                       _this.pageCount = PageInfo.pageCount;

                       for (var i = 0; i < data.KangjunyaowuList.length; i++) {
                           var mmKangjunyaowu = data.KangjunyaowuList[i];

                           var mmPinzhong = mmKangjunyaowu.pinzhong;
                           var mmPinguiList = mmKangjunyaowu.pinguilist;
                           var mmPinzhongHebingshu = mmKangjunyaowu.pinzhonghebinghang;

                           for (var j = 0; j < mmPinguiList.length; j++) {
                               var s=0;

                               var mmPinguilist = mmPinguiList[j];
                               var mmPingui = mmPinguilist.pingui;
                               var mmYaopinmingcheng = mmPinguilist.yaopinmingcheng;
                               var mmXianzhishu = mmPinguilist.xianzhishu;
                               var mmGuizebianhao = mmPinguilist.guizebianhao;
                               var mmFenlei = mmPinguilist.fenlei;
                               var mmXianzhitiaojian=mmPinguilist.xianzhitiaojian;
                               var mmHebinghang=mmPinguilist.hebinghang;
                               var mmGuige = mmPinguilist.guige;
                               var mmDanwei = mmPinguilist.danwei;
                               var mmJiage = mmPinguilist.jiage;
                               var mmYibaoleibie = mmPinguilist.yibaoleibie;
                               var mmGuojiajibenyaowu = mmPinguilist.guojiajibenyaowu;
                               var mmJicaiyao = mmPinguilist.jicaiyao;
                               var mmTongguopingjia = mmPinguilist.tongguopingjia;
                               var mmZhidaoyuanze = mmPinguilist.zhidaoyuanze;
                               var mmDongzongyao = mmPinguilist.dongzongyao;
                               var mmDongzongjilu2="";
                               if(mmPinguilist.dongzongjilu2!=undefined){
                                   var mmDongzongjilu2 = mmPinguilist.dongzongjilu2;
                               }
                               var mmQinhuaiyao = mmPinguilist.qinhuaiyao;

                               var mmQinhuaijilu2="";
                               if(mmPinguilist.qinhuaijilu2!=undefined){
                                   var mmQinhuaijilu2 = mmPinguilist.qinhuaijilu2;
                               }
                               var mmZhidaoyijian = mmPinguilist.zhidaoyijian;
                               var mmBeizhu=mmPinguilist.beizhu;
                               var mmPinzhongpaiming=mmPinguilist.pinzhongpaiming;
                               var mmPinguipiaoshu=mmPinguilist.pinguipiaoshu;
                               var mmHuanhangfu = "";
                               var mmyijihe="";
                               var mmerjihe="";
                               if(j==0 &&s==0){
                                   mmyijihe= "<td style='text-align:center;vertical-align:middle;width: 49px;height: 100%'  rowspan='" + mmPinzhongHebingshu + "'>" + mmPinzhong + "</td>";
                                   mmerjihe= "<td style='text-align:center;vertical-align:middle;width: 49px;height: 100%'  rowspan='" + mmPinzhongHebingshu + "'>" + mmPinzhongpaiming + "</td>";
                                   s= 1;
                               }
                               mmHtml +=mmyijihe;
                               mmHtml += mmHuanhangfu + "<td style='text-align:center;vertical-align:middle;'>" + mmPingui + "</td>";
                               mmHtml += "<td style='text-align:center;vertical-align:middle;'>" + mmYaopinmingcheng + "</td>";
                               mmHtml += "<td style='text-align:center;vertical-align:middle;'>" + mmFenlei + "</td>";
                            /*   if(mmHebinghang!=null&&mmHebinghang!=0){
                                   mmHtml+= "<td style='text-align:center;vertical-align:middle;width: 49px;height: 100%'  rowspan='" + mmHebinghang + "'>" + mmXianzhitiaojian + "</td>";
                               }
                               if(mmHebinghang==""){
                                   mmHtml += "<td style='text-align:center;vertical-align:middle;'>" + mmXianzhitiaojian + "</td>";
                               }*/

                               mmHtml += "<td style='text-align:center;vertical-align:middle;white-space:nowrap;text-overflow: ellipsis; overflow: hidden;'><a title='" + mmGuige + "'>" + mmGuige + "</a></td>";
                             /*  mmHtml += "<td style='text-align:center;vertical-align:middle;'>" + mmJiage + "</td>";*/
                               mmHtml += "<td style='text-align:center;vertical-align:middle;'>" + mmDanwei + "</td>";
                               mmHtml += "<td style='text-align:center;vertical-align:middle;'>" + mmYibaoleibie + "</td>";
                               mmHtml += "<td style='text-align:center;vertical-align:middle;'>" + mmGuojiajibenyaowu + "</td>";
                               mmHtml += "<td style='text-align:center;vertical-align:middle;'>" + mmJicaiyao + "</td>";
                               mmHtml += "<td style='text-align:center;vertical-align:middle;'>" + mmTongguopingjia + "</td>";
                                mmHtml += "<td style='text-align:center;vertical-align:middle;'>" + mmZhidaoyuanze + "</td>";
                                mmHtml += "<td style='text-align:center;vertical-align:middle;'>" + mmDongzongyao + "</td>";
                                mmHtml += "<td style='text-align:center;vertical-align:middle;'>" + mmQinhuaiyao + "</td>";
                                mmHtml += "<td style='text-align:center;vertical-align:middle;'>" + mmDongzongjilu2 + "</td>";
                                mmHtml += "<td style='text-align:center;vertical-align:middle;'>" + mmQinhuaijilu2 + "</td>";
                                /*mmHtml += "<td style='text-align:center;vertical-align:middle;'>" + mmZhidaoyijian + "</td>";
                                mmHtml += "<td style='text-align:center;vertical-align:middle;white-space:nowrap;text-overflow: ellipsis; overflow: hidden;'><a title='" + mmBeizhu + "'>" + mmBeizhu + "</a></td>";*/
                               mmHtml +=mmerjihe;
                               mmHtml += "<td style='text-align:center;vertical-align:middle;'>" + mmPinguipiaoshu + "</td>";
                                mmHtml += "</tr>";

                                }
                            }

                        }else {
                            _this.show = false;
                        }
                        mmHtml += "</table>";
                        $("#List").html(mmHtml);
                    }else{
                        layer.alert(ppData.message);
                    }
                }

            },"json");
        },

        //跳到首页
        SetPageIndex : function(){
            this.pageIndex = 1;
        },
        SetPageEnd : function(){
            this.pageIndex = this.pageCount;
        },
        //上一页
        SetPageIndexPrePage : function(){
            var PrePage = ((this.pageIndex -1) <= 0) ? 1 : (this.pageIndex -1);
            this.pageIndex = PrePage;
        },
        //下一页
        SetPageIndexNextPage : function(){
            var NextPage = ((this.pageIndex +1) >= this.pageCount) ? this.pageCount : (this.pageIndex +1);
            this.pageIndex = NextPage;
        },
        //跳转界面
        JumpPage : function(){
            if(this.inputPageIndexValue <= 1){
                this.inputPageIndexValue = 1;
            }else if(this.inputPageIndexValue >= this.pageCount){
                this.inputPageIndexValue = this.pageCount;
            }
            this.pageIndex = this.inputPageIndexValue;
            this.inputPageIndexValue = '';
        },

    },
    watch :{
        //监控分页情况，刷新列表
        pageIndex : function(){

            this.bindKangjunyaowuList();
        }
    }
});
